﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeiTool.Log
{
    internal class LogMethod
    {
        public static string WriteTxtData(string logMesage, string logFileName, string logPath)
        {
            CreateDirectory(logPath);
            var urldata = logPath + logFileName + ".txt";

            if (!File.Exists(urldata))
            {
                FileStream fs = File.Create(urldata);
                fs.Close();
            }
            StreamWriter sw = File.AppendText(urldata);
            logMesage = $"---{DateTime.Now:yyyy-MM-dd HH:mm:ss}---  " + logMesage;
            sw.WriteLine(logMesage);
            sw.Close();

            return urldata;
        }

        /// <summary>
        /// 创建文件目录
        /// </summary>
        /// <param name="targetDir"></param>
        public static void CreateDirectory(string targetDir)
        {
            DirectoryInfo dir = new DirectoryInfo(targetDir);
            if (!dir.Exists)
                dir.Create();

        }
    }
}
